package src_noe;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;

 
public class Frame extends JFrame{
	//Declaration de variables
	private int heure=0,minute=0,seconde=0;
	private int delais=1000;
	final JButton debut = new JButton("Pause");
	JLabel label;
	JPanel Panel1=new JPanel();

	
	private ActionListener tache_timer;
	private Timer timer1;
 
//methode start
public void start(){
	timer1.stop();}
   //methode pause
public void pause(){
	timer1.start();}

	public Frame(){
		setSize(200,200);
		Panel1.add(debut);
		label=new JLabel(""+heure+":"+minute+":"+seconde);
		label.setFont(new Font("sansserif", Font.PLAIN, 48));
  
		getContentPane().add(label,"Center");
		getContentPane().add(Panel1,"South");

		
		chrono();
	}
 
	//Methode pour lancer notre chrono
	public void chrono(){
		tache_timer= new ActionListener()  {
		  public void actionPerformed(ActionEvent e1)  {
		    seconde++;
		     if(seconde==60)  {
		          seconde=0;
		          minute++;
		      }
		  if(minute==60) {
		      minute=0;
		      heure++;
		  }
		  //Afficher le chrono dans un JLabel
		  label.setText(heure+":"+minute+":"+seconde);
		
		 }
     };
     //Action et temps execution de la tache
     timer1=new Timer(delais,tache_timer);
     //Demarrer le chrono à l ouverture de la fenetre(si c 'est pas necessaire tu l'enleve)
    pause();
    
	
	debut.addActionListener(new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			String texte;
			texte=debut.getText();
			if(texte.compareTo("Pause")==0)
			{
				debut.setText("Start");
				start();
			}
			else if(texte.compareTo("Start")==0)
			{
				debut.setText("Pause");
				pause();
			}
		}
	});}
	 public static void main(String[] args){
		 
	 Frame f=new Frame();
	 f.setVisible(true);
	}
}